#!/user/bin/env python
# -*- coding: UTF-8 -*-
# Author: xieyuheng
# Date: 2024/2/26
"""
该文件用于 记录代码的各种不同路径和读取yml的数据
"""
import os
import yaml
import constant

class ReadConfig(object):
    """读取配置文件"""
    data = None

    @classmethod
    def correct_yaml(cls, data):
        """
        修改文件
        :param data: 修改文件的数据
        :return:
        """
        ReadConfig.data = None
        with open(constant.config_path, mode="w") as file:
            yaml.dump(data, file)

    @classmethod
    def read_yaml(cls, file_yaml):
        """
        读取文件
        :param file_yaml: 文件路径
        :return: 文件内容
        """
        if os.path.exists(file_yaml):
            file_yaml = file_yaml
        else:
            raise FileNotFoundError("yml文件不存在")
        if not ReadConfig.data:
            with open(file_yaml, mode='rb') as file:
                datas = yaml.load(file, Loader=yaml.FullLoader)
                cls.data = datas
        return cls.data


class FilePath:
    """记录文件路径"""

    def __init__(self):
        self.data = ReadConfig.read_yaml(constant.config_path)

    @property
    def soft_install_path(self):
        """

        :return: 软件安装路径
        """
        return self.data['soft_install']['path']

    @property
    def colse_app_kill_appname(self):
        """

        :return: 关闭的APP名称
        """
        return self.data['close_app_kill']['app_name']

    @property
    def execute_way(self):
        """

        :return: 执行方式
        """
        return self.data['execute_way']

    @property
    def execute_file(self):
        """

        :return: 执行文件
        """
        return self.data['execute_file']

    @property
    def resolution_width(self):
        """

        :return: 分辨率宽
        """
        return self.data['resolution']['width']


    @property
    def resolution_height(self):
        """

        :return: 分辨率高
        """
        return self.data['resolution']['height']

    @property
    def project_new_project_name(self):
        """

        :return: 新建文件名称
        """
        return self.data['project']['new_project_name']


    @property
    def enter_pass_user(self):
        """

        :return: 先临通行证账号
        """
        return self.data['enter_pass']['user']

    @property
    def enter_pass_password(self):
        """

        :return: 先临通行证密码
        """
        return self.data['enter_pass']['password']

    @property
    def launch_app(self):
        """

        :return: exe启动文件
        """
        return self.data['launch_app']['app'].replace('${soft_install_path}', readconfig.soft_install_path)

    @property
    def proc_exist_process_name(self):
        """

        :return: 先临通行证名称
        """
        return self.data['proc_exist']['process_name']

    @property
    def language_source_path(self):
        """

        :return: 更换语言文件路径
        """
        return self.data['language']['source_path'].replace('${soft_install_path}', readconfig.soft_install_path)

    @property
    def app_name(self):
        """

        :return: 软件名称
        """
        return self.data['app']['name']

    @property
    def is_need_relaunch(self):
        """

        :return: 每次是否重启软件
        """
        return self.data['is_need_relaunch']

    @property
    def config_editor_path(self):
        """

        :return: configEditor的软件中位置
        """
        return self.data['configEditor_path'].replace('${soft_install_path}', readconfig.soft_install_path)

    @property
    def config_db_path(self):
        """

        :return: configDB的软件中位置
        """
        return self.data['config_db_path'].replace('${soft_install_path}', readconfig.soft_install_path)

    @property
    def read_pic_is_read_image(self):
        """

        :return: 修改的读图的值
        """
        return self.data['read_pic']['is_read_image']

    @property
    def read_pic_read_pic_mode(self):
        """

        :return: 修改的读图的模式
        """
        return self.data['read_pic']['read_pic_mode']

    @property
    def read_pic_read_write_switch(self):
        """

        :return: 修改的白平衡的值
        """
        return self.data['read_pic']['read_write_switch']

    @property
    def read_pic_device_type(self):
        """

        :return: 设备的类型
        """
        return self.data['read_pic']['device_type']


readconfig = FilePath()

if __name__ == '__main__':
    print(readconfig.enter_pass_user)
    print(readconfig.enter_pass_password)
